package com.label.Model.Do;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;
import org.apache.xerces.impl.dv.dtd.IDDatatypeValidator;

import java.io.Serializable;
import java.util.Date;

@TableName(value = "job")
@Data
public class Job implements Serializable {

    @TableId(value = "job_id",type = IdType.ASSIGN_ID)
    private Long id;

    @TableField(value = "job_name")
    private String name;

    @TableField(value = "job_state")
    private String state;

    @TableField(value = "job_result")
    private String result;

    @TableField(value = "job_author")
    private String creator;

    @TableField(value = "job_time",fill = FieldFill.INSERT_UPDATE)
    @JsonFormat( pattern = "yyyy-MM-dd HH:mm:ss" )
    private Date time;

    @TableField(value = "job_dim")
    private String dim;

    @TableField(value = "strategy_id")
    private String strategyId;

    @TableField(value = "persons_id")
    private Long personsId;

    @TableField(value = "job_type")
    private String jobType;

    @TableField(exist = false)
    private Strategy strategy;

    @TableField(exist = false)
    private Persons persons;

    @JsonProperty("personName")
    private String personNameJSON() {
        if(persons!=null)
            return persons.getName();
        return null;
    }

    @JsonProperty("strategyName")
    private String strategyJSON() {
        if(strategy!=null)
            return strategy.getName();
        return null;
    }


    public Job(){}

    public Job(String creator){
        this.creator=creator;
    }

}
